<?php

namespace app\common\model;
use Think\Db;
/**
 * 收藏模型
 */
class Collect extends Base{
	//添加收藏
	public function add($uid,$bookid,$model) {
		if($model==2){
			$name = Db::name('cartoon')->where('id= '.$bookid)->cache(true,600)->value('name');
		}else{
			$name = Db::name('novel')->where('id= '.$bookid)->cache(true,600)->value('title');
		}
		$data['uid'] = $uid;
		$data['created_at'] = time();
		$data['model'] = $model;
		$data['cartoon_id'] = $bookid;
		$data['cartoon_name'] = $name;
		$res = Db::name('collect')->insert($data);
		return $res;
		
	}
	//删除收藏
	public function del($uid,$bookid,$model){
		$res = db('collect')->where(array('model'=>$model,'cartoon_id'=>$bookid,'uid'=>$uid))->delete();
		return $res;
	}
	
	//查询收藏
	public function find($uid,$bookid,$model) {
		$collect = db('collect')->where(array('model'=>$model,'cartoon_id'=>$bookid,'uid'=>$uid))->find();
		if($collect){
			return 1;
		}else{
			return 0;
		}
	}

}